#include "stdafx.h"
#include "EntityManagerScene.h"
#include "Entity/EntityDefinition.h"
#include "Entity/EntityVisitorCombat.h"



EntityManagerCombat::EntityManagerCombat()
:m_nIDGenerator(0)
{
}

EntityManagerCombat::~EntityManagerCombat()
{
}

bool
EntityManagerCombat::addEntity(int nID, IEntity* e)
{
	if (e->getType()==Entity::ett_Player)
	{
		//
		//	note that player is not a combat entity
		//	only its sub roles will be added into entity manager for combat
		//
		IEntityManager* pSubRoles = e->getEntityMgr();
		if (pSubRoles)
		{
			EntityVisitorCombatRole visitor(*this);
			pSubRoles->forEach(visitor);
		}
		return true;
	}
	else
	{
		if (nID == 0)
		{
			do 
			{
				nID = ++m_nIDGenerator;
			}
			while(nID==0 || NULL!=getEntity(nID));
		}

		return __super::addEntity(nID, e);
	}
}





EntityManagerCity::EntityManagerCity()
:m_nIDGenerator(0)
{
}

EntityManagerCity::~EntityManagerCity()
{
}

bool
EntityManagerCity::addEntity(int nID, IEntity* e)
{
	if (nID == 0)
	{
		do 
		{
			nID = ++m_nIDGenerator;
		}
		while(nID==0 || NULL!=getEntity(nID));
	}

	return __super::addEntity(nID, e);
}